package com.yanfan.elevator.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.elevator.domain.IbmsElevatorDevice;
import com.yanfan.elevator.service.IIbmsElevatorDeviceService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 电梯系统设备Controller
 *
 * @author genluo
 * @date 2024-08-27
 */
@Api(tags = "电梯系统设备")
@RestController
@RequestMapping("/elevator/elevatorDevice")
public class IbmsElevatorDeviceController extends BaseController {
    @Autowired
    private IIbmsElevatorDeviceService ibmsElevatorDeviceService;

    /**
     * 查询电梯系统设备列表
     */
    @ApiOperation("电梯系统设备分页列表")
    @PreAuthorize("@ss.hasPermi('elevator:elevatorDevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsElevatorDevice ibmsElevatorDevice) {
        startPage();
        List<IbmsElevatorDevice> list = ibmsElevatorDeviceService.queryPageList(ibmsElevatorDevice);
        return getDataTable(list);
    }

    /**
     * 导出电梯系统设备列表
     */
    @ApiOperation("导出电梯系统设备列表")
    @PreAuthorize("@ss.hasPermi('elevator:elevatorDevice:export')")
    @Log(title = "电梯系统设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsElevatorDevice ibmsElevatorDevice) {
        List<IbmsElevatorDevice> list = ibmsElevatorDeviceService.queryPageList(ibmsElevatorDevice);
        ExcelUtil<IbmsElevatorDevice> util = new ExcelUtil<IbmsElevatorDevice>(IbmsElevatorDevice.class);
        util.exportExcel(response, list, "电梯系统设备数据");
    }

    /**
     * 获取电梯系统设备详细信息
     */
    @ApiOperation("获取电梯系统设备详细信息")
    @PreAuthorize("@ss.hasPermi('elevator:elevatorDevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ibmsElevatorDeviceService.getById(id));
    }

    /**
     * 新增电梯系统设备
     */
    @ApiOperation("新增电梯系统设备")
    @PreAuthorize("@ss.hasPermi('elevator:elevatorDevice:add')")
    @Log(title = "电梯系统设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IbmsElevatorDevice ibmsElevatorDevice) {
        return toAjax(ibmsElevatorDeviceService.save(ibmsElevatorDevice));
    }

    /**
     * 修改电梯系统设备
     */
    @ApiOperation("修改电梯系统设备")
    @PreAuthorize("@ss.hasPermi('elevator:elevatorDevice:edit')")
    @Log(title = "电梯系统设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IbmsElevatorDevice ibmsElevatorDevice) {
        return toAjax(ibmsElevatorDeviceService.updateById(ibmsElevatorDevice));
    }

    /**
     * 删除电梯系统设备
     */
    @ApiOperation("删除电梯系统设备")
    @PreAuthorize("@ss.hasPermi('elevator:elevatorDevice:remove')")
    @Log(title = "电梯系统设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ibmsElevatorDeviceService.removeBatchByIds(Arrays.asList(ids)));
    }
}
